package personnel.department.pages.addpage;

import java.util.List;
import java.util.Set;

import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;

import personnel.department.dao.entity.AdoptedToStructural;
import personnel.department.pages.PDTable;

public class AdoptedToStructuralEditor extends AbstractTableEditor<AdoptedToStructural> {


	public AdoptedToStructuralEditor(CTabFolder tabFolder) {
		super(tabFolder, "Принят в подразделение");
	}
	
	public AdoptedToStructuralEditor(CTabFolder tabFolder, Set<AdoptedToStructural> adoptedToStructurals) {
		super(tabFolder, "Принят в подразделение", adoptedToStructurals);
	}

	@Override
	public PDTable<AdoptedToStructural> createTable(Composite parent) {
		return new PDTable<AdoptedToStructural>(parent) {

			@Override
			public List<AdoptedToStructural> setModelProvider() {
				return getModel();
			}

			@Override
			protected void createColumns(Composite parent, TableViewer viewer) {
				String[] titles = { "Номер договора", "Основная работа", "Структурное подразделение", "Внешнее совместительство", "Внутреннее совместительство", "Ставка"};
				int[] bounds = { 130, 150, 170, 170, 180, 100};

				TableViewerColumn col = createTableViewerColumn(getViewer(), titles[0], bounds[0], 0);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						AdoptedToStructural e = (AdoptedToStructural) element;
						return String.valueOf(e.getNumberContract());
					}
				});

				col = createTableViewerColumn(getViewer(), titles[1], bounds[1], 1);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						AdoptedToStructural e = (AdoptedToStructural) element;
						return String.valueOf(e.getWork().getBaseWork());
					}
				});

				col = createTableViewerColumn(getViewer(), titles[2], bounds[2], 2);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						AdoptedToStructural e = (AdoptedToStructural) element;
						return e.getSubdivision().getSubdivisionName();
					}
				});

				col = createTableViewerColumn(getViewer(), titles[3], bounds[3], 3);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						AdoptedToStructural e = (AdoptedToStructural) element;
						return e.getWork().getExternalWork();
					}
				});

				col = createTableViewerColumn(getViewer(), titles[4], bounds[4], 4);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						AdoptedToStructural e = (AdoptedToStructural) element;
						return e.getWork().getInternalWork();
					}
				});

				col = createTableViewerColumn(getViewer(), titles[5], bounds[5], 5);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						AdoptedToStructural e = (AdoptedToStructural) element;
						return String.valueOf(e.getRate());
					}
				});

			}
		};
	}

}
